<template>
  <div class="px-60">
    <div class="block">
      <ol class="list-decimal list-outside space-y-5 font-sans text-lg">
        <li 
          v-for="question in questions"
          class=""
        >
          <div class="px-3 text-left mb-3">{{ question.description }}</div>
          <div class="flex-col justify-start">
            <div v-for="option in question.options" class="flex justify-start">
              <input type="radio" v-model="question.choosen" :value="option" :name="question.name"/>
              <label class="px-2" :for="option">{{ option }}</label>
            </div>
          </div>
        </li>
      </ol>
    </div>
    <div class="block">
      <button @click="getScore"
        class="px-2 py-1 m-2
            text-purple-600 font-semibold
            rounded border border-purple-200
            enabled:hover:text-white enabled:hover:bg-purple-600"
      >
        submit
      </button>
      <label v-if="score!=''">score: {{ score }}</label>
    </div>
    <div>
      <button @click="dialogVisible = true"
        class="px-2 py-1 m-2
            text-purple-600 font-semibold
            rounded border border-purple-200
            enabled:hover:text-white enabled:hover:bg-purple-600"
      >
        solution
      </button>
    </div>
  </div>
  <el-dialog
    v-model="dialogVisible"
    title="solution"
  >
    <v-md-preview style="text-align: start" :text="solution"></v-md-preview>
  </el-dialog>
</template>

<script>

export default {
  name: 'Test',
  data() {
    return {
      dialogVisible: false,
      questions: [
        {
          name: 'question1',
          description: 'What is the primary purpose of Role-Based Access Control (RBAC) in a system?',
          options: [
            "a) To restrict access based on a user's job function",
            "b) To monitor user activity within a system",
            "c) To grant access based on the user's age",
            "d) To manage the storage capacity of a system"
          ],
          answer: "a) To restrict access based on a user's job function",
          choosen: '',
        },
        {
          name: 'question2',
          description: 'Which of the following best describes the term "principle of least privilege" in the context of Role-Based Access Control?',
          options: [
            "a) Users should have access to every resource they might need",
            "b) Users should only have access to resources necessary for their job function",
            "c) Users should not be allowed to access any resources",
            "d) Users should be granted temporary access to resources"
          ],
          answer: "b) Users should only have access to resources necessary for their job function",
          choosen: '',
        },
        {
          name: 'question3',
          description: 'In the context of RBAC, what is the primary function of a role hierarchy?',
          options: [
            "a) To determine which users have the most experience",
            "b) To assign users to different departments",
            "c) To enable inheritance of permissions from one role to another",
            "d) To measure the performance of users in their respective roles"
          ],
          answer: 'c) To enable inheritance of permissions from one role to another',
          choosen: '',
        },
        {
          name: 'question4',
          description: 'Which of the following is NOT a component of Role-Based Access Control?',
          options: [
            "a) Users",
            "b) Roles",
            "c) Permissions",
            "d) Password strength"
          ],
          answer: 'd) Password strength',
          choosen: '',
        },
      ],
      score: '',
      solution: `
# Question 1
The primary purpose of Role-Based Access Control (RBAC) in a system is to restrict access based on a user's job function. RBAC provides a way to manage permissions and access to resources based on the roles assigned to users, rather than granting permissions directly to each user. This simplifies administration, enhances security, and allows for better separation of duties.
# Question 2
The term "principle of least privilege" in the context of Role-Based Access Control means that users should only have access to resources necessary for their job function. This approach minimizes the risk of unauthorized access or misuse of sensitive information by limiting user access to the minimum level required to perform their tasks.
# Question 3
In the context of RBAC, the primary function of a role hierarchy is to enable inheritance of permissions from one role to another. This means that if a role has a higher position in the hierarchy, it inherits the permissions of the roles below it. This hierarchy simplifies the management of permissions, as common permissions can be assigned to lower-level roles, while specific permissions can be assigned to higher-level roles as needed.
# Question 4
Password strength is NOT a component of Role-Based Access Control. RBAC consists of users, roles, and permissions. Users are individuals who access the system, roles are predefined sets of permissions that represent a specific job function, and permissions define the actions or resources that can be accessed by a user with a particular role. Password strength, on the other hand, is related to authentication and securing user accounts, rather than defining their access within the system.
      `,
    };
  },
  methods: {
    getScore() {
      this.score = 0;
      this.questions.forEach(question => {
        if(question.choosen == question.answer) {
          this.score += 1;
        }
      });
    }
  },
};
</script>
